<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String fgId = request.getParameter("fgId");
%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta content="B2B电商平台" name="description"/>
<meta content="B2B电商平台" name="keyword"/>

<title>B2B电商平台.满赠活动维护</title>
<link rel="icon" href="include/images/icss.ico" type="image/x-icon" />
<link rel="shortcut icon" href="include/images/icss.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="<%=path %>/include/css/global.css" />
<link rel="stylesheet" type="text/css" href="<%=path %>/include/css/style.css" />
<link rel="stylesheet" type="text/css" href="<%=path %>/include/css/pro.css" />
<link rel="stylesheet" type="text/css" href="<%=path %>/include/css/proManage.css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/include/pagination/page.css" media="all">
<script type="text/javascript" src="<%=path %>/include/js/jquery-1.8.0.min.js"></script>
<script src="<%=path%>/include/DatePicker/WdatePicker.js" charset="UTF-8" type="text/javascript"></script>

<script type="text/javascript" src="<%=path %>/include/js/cookies.js"></script>
<script type="text/javascript" src="<%=path %>/include/js/icss.busin.js"></script>
<script type="text/javascript" src="<%=path %>/include/js/icss.common.js"></script>

<style type="text/css">
.price a.price_rise {
    background-position: -62px -136px;
}
.price a.price_drop {
    background-position: -62px -95px;
}
.price a.price_null {
    background-position: -62px -15px;
    padding-right: 0px;
}
.expire a.expire_drops {
    background-position: -61px -95px;
}
.expire a.expire_rise {
    background-position: -61px -136px;
}
.expire a.expire_null {
    background-position: -61px -15px;
    padding-right: 0px;
}
.colnums-2-ab-b {
    float: left;
    width: 100%;
    height: auto;
    font-size: 12px !important;
}

.listed_tb_k th.t1 {
    width: 5%;
    border-right: 1px solid #fff;
    padding: 0 5px;
}
.listed_tb_k th.t2 {
    width: 15%;
    border-right: 1px solid #fff;
}
.listed_tb_k th.t3 {
    width: 35%;
    border-right: 1px solid #fff;
}
.listed_tb_k th.t4 {
    width: 15%;
    border-right: 1px solid #fff;
}
.listed_tb_k th.t5 {
    width: 15%;
    border-right: 1px solid #fff;
}
.listed_tb_k th.t6 {
    width:15%;
    border-right: 1px solid #fff;
}
.listed_tb_k th.t7 {
    width: 8%;
    border-right: 1px solid #fff;
}
.productName {
    border: 1px solid #FFF;
    width: 300px;
    height: 50px;
    display: table-cell;
    vertical-align: middle;
    text-align: center;
    background-color: #fff;
}
.listed_tb_k tbody td.t2 .pic_50 {
    border: 1px solid #FFF;
    width: 50px;
    height: 50px;
    display: table-cell;
    vertical-align: middle;
    text-align: center;
    background-color: #fff;
}
.t1 {
    border-right: 1px solid #ddd;
}
.t2 {
    border-right: 1px solid #ddd;
} 
.t3 {
    border-right: 1px solid #ddd;
}   
.t4 {
    border-right: 1px solid #ddd;
}
.t5 {
    border-right: 1px solid #ddd;
}
.t6 {
    border-right: 1px solid #ddd;
}
.t7 {
    border-right: 1px solid #ddd;
}        
    
.toptil {
    border: 1px solid #e0e0e0;
    border-bottom: 2px solid #f13e41;
    background: #f5f5f5;
    line-height: 35px;
    margin-bottom: 0px;
    padding: 0 10px;
    font-size: 14px;
    font-weight: bold;
}
.cxx_btn {
    width: 44px;
    height: 24px;
    background-position: 0 -203px;
    line-height: 24px;
    margin: 0 0 5px;
    background-image: url(img/xs_bgx.png);
    background-repeat: no-repeat;
    background-color: transparent;
}
.search_lis .search_lis_se {
    width: 700px;
}
#listTable th {
	line-height: 30px;
	border: 1px solid #ddd;
	font-weight: bold;
}

#ajaxSerieslist td {
	border: 1px solid #ddd;
}

</style>

<script type="text/javascript">
$(document).ready(function() {
	_reHeight("rightFrame","contentDiv");
	var pid = "<%=fgId%>";
	if(pid!=null&&pid!=""){
		$("#fgId").val(pid);
		var range = "${bean.FG_RANGE}"=="1"?"1":"2";
		$("#fgRange").val(range);
		var useType = "${bean.USE_TYPE}"=="1"?"1":"2";
		$("#useType").val(useType);
		var useCalcType = "${bean.USE_CALC_TYPE}"=="2"?"2":"1";
		$("#useCalcType").val(useCalcType);
		var giftType = "${bean.GIFT_TYPE}"=="1"?"1":"2";
		$("#giftType").val(giftType);
		$("#status").val("${bean.STATUS}");
		$("#timesFg").val("${bean.TIMES_FG}");
		
		_viewProductList();
		if("${flag}"=="info"){
			 $("#submitformdata").css("display","none");
			 $("#submitformdata1").css("display","");
			 $("#fgRange").attr("disabled", "disabled"); 
			 $("input[name='checkboxAll']").removeAttr("onclick");
		}
		_changeUseCalcType();
	}
	_initDataList();
});


	//处理查询条件的默认值
    //参数：id;ovalue原值;nvalue 新值; type：事件类型（1表示获取焦点 2表示失去焦点）
    function clearDefaultVal(id,type,ovalue,nvalue){
        if(type==1){//判断事件类型(获取焦点,情况现有默认值)
            jQuery("#"+id).val(nvalue);
        }else{
            //失去焦点，值为空，赋默认值
            if(nvalue==""){
                jQuery("#"+id).val(ovalue);
            }
        }
    }

    function _viewProductList(){
    	var fw = $("#fgRange").val();
    	if(fw=="2"){
    		_initDataList();
    		$("#productList").show();
        }else{
            $("#productList").hide();
        }
        
    }
    
	function _getSelect(){
		
		jQuery.ajax({
			type:"post",
			url: "<%=path %>/fullGift/queryProductTypeList.do",
			dataType: "json",
			data: {
				firstSeries : $("#firstSeries").val(),
				level : 2
			},
			success:function(data){
				if(data!=null){
					jQuery("#secondSeries").empty();
					 jQuery("#secondSeries").prepend("<option value='0'>全部</option>");   //为Select插入一个Option(第一个位置)
					for(var i=0; i<data.length; i++){
						//为Select追加一个Option(下拉项)
					    jQuery("#secondSeries").append("<option value='"+data[i].PRODUCT_TYPE_CODE+"'>"+data[i].PRODUCT_TYPE_NAME+"</option>");
					}
				}
			}
		});

	}
	
	function _initDataList() {
		var title = $("#queryTitle").val();
		if(title =="请输入商品标题..."){
			title = "";
		}
		var minPriceStr = $("#minPriceStr").val(); 
		var maxPriceStr = $("#maxPriceStr").val(); 
		if(minPriceStr =="最低价格"){
			minPriceStr = "";
		}else{
			if(isNaN(minPriceStr)){
				return;
			}
		}
		if(maxPriceStr =="最高价格"){
			maxPriceStr = "";
		}else{
			if(isNaN(maxPriceStr)){
				return;
			}
		}
		var firstSeries = $("#firstSeries").val(); 
		var secondSeries = $("#secondSeries").val(); 
		//$("#productList").show();
		$.ajax({
			type:"post",
			url: "<%=path %>/fullGift/queryProductList.do",
			dataType:"json",
			data:{
				firstSeries : firstSeries,
				secondSeries: secondSeries,
				title: title,
				minPriceStr:minPriceStr,
				maxPriceStr:maxPriceStr,
				fgId:$("#fgId").val()
				},
			success:function(data){
				var str = "";
				$("#ajaxSerieslist").empty();
				for(var i=0;i<data.length;i++){
					str += "<tr>";
					str += "    <td class='t1' style='text-align:center;vertical-align: middle'>";
					if(data[i].FG_PRO_ID=="0"){
						str += " 		<input type='checkbox' name='productId' value='"+data[i].PRODUCT_ID+"' star='3' mainpro=''>";
					}else{
						str += " 		<input type='checkbox' name='productId' checked='checked' value='"+data[i].PRODUCT_ID+"' star='3' mainpro=''>";
					}
					str += "    </td>";
					str += "    <td class='t2' style='text-align:center;vertical-align: middle'>";
					str += "    	<div class='pic_50'>";
				//	str += "    		<a href='http://b2b.hc360.com/supplyself/597339459.html' target='_blank'>";
					str += "    		<a>";
					str += "        		<img src='" + data[i].PRODUCT_PIC + "' width='50' height='50' alt='' resizeimg='true' onmousedown='' onerror='javascript:this.src=\"http://img.b2b.hc360.com/pubimages/noimg.gif\";' style='width: 35px; height: 35px;'>";
					str += "    		</a>";
					str += " 		</div>";
					str += "	</td>";
					str += " 	<td class='t4' style='text-align:left;vertical-align: middle'>";
					str += "		<p>";
				//	str += "			<a href='http://b2b.hc360.com/supplyself/597339459.html' target='_blank'>"+data[i].PRODUCT_NAME+"</a>";
					str += "			<a>"+data[i].PRODUCT_NAME+"</a>";
					str +="			</p>";
					str +=" 	</td>";
					str +="		<td class='t4' style='text-align:center;vertical-align: middle'>"+data[i].PRODUCT_PRICE+"元</td>";	
					str +="		<td class='t4' id='pubdateTd'  style='text-align:center;vertical-align: middle'>";
					str +=" 		<span >"+data[i].PRODUCT_STOCK+"</span>";
					str +=" 	</td>";
					str +=" 	<td class='t4' style='text-align:center;vertical-align: middle'>";
					str +=" 		<span class='pubdateSpan'>"+data[i].UP_DATE+"</span>";
					str +=" 	</td>";	                
					str +=" </tr>";
				}
				$("#ajaxSerieslist").append(str);
				_reHeight("rightFrame","contentDiv");
			}
			});	
 	}

	 function _add(){
			var fgId =  $("#fgId").val();
		 	var fgName =  $("#fgName").val();
			var begTime =  $("#begTime").val();
			var endTime =  $("#endTime").val();
			var fgRange =  $("#fgRange").val();
			var useType =  $("#useType").val();
			var useCondition =  $("#useCondition").val();
			var status =  $("#status").val();
			var timesFg =  $("#timesFg").val();
			var useCalcType = $("#useCalcType").val();
			var giftType = $("#giftType").val();

			if(fgName==""){
			 	parent.swal("活动名称必须填写!");
				return;
			}
			if(begTime==""){
		    	parent.swal("开始时间必须选择!");
			    return;
			}
			if(endTime==""){
		    	parent.swal("结束时间必须选择!");
			    return;
			}
			
			if(begTime > endTime){
				parent.swal("", "开始时间不得大于结束时间！", "error");
				return;
			}
			
			if(useCondition==""){
		    	parent.swal("使用条件必须填写");
			    return;
			}
			var url = "<%=path %>/fullGift/save.do";
			if(fgId=="-1"){
				url += "?flag=add";
			}else{
				url += "?flag=update";
			}
	        var proIds ="";
	    	 $("input[name='productId']").each(function(index,item){
	    		 if($(this).attr("checked")=="checked"){
	    			 proIds += $(this).val()+",";
	        	 }
		    })
		    if(proIds==""&&fgRange=="2"){
		    	parent.swal("请至少选择一种商品参加活动!");
			    return;
			}else{
				$.ajax({
					type:"post",
					url: url,
					data:{
						  proIds:proIds,
						  fgName :fgName,
						  fgId :fgId,
						  begTime :begTime,
					      endTime :endTime,
					      fgRange :fgRange,
					      useType :useType,
					      useCondition :useCondition,
					      timesFg :timesFg,
					      useCalcType :useCalcType,
					      giftType :giftType,
					      status :status
						},
					dataType:"json",
					beforeSend:function(){
						$("#submitformdata").attr("disabled", true); 
					},
					success:function(data){
						$("#fgId").val(data.msg);
						if(data.success){
							parent.swal("保存成功!");
						}else{
							parent.swal("保存失败!");
						}
						$("#submitformdata").attr("disabled", false); 
					}
				});
			}
	    }
	function _checkZhekou(obj){
		var value = obj.value;
		if(isNaN(value)){
			parent.swal("请输入数值!");
			obj.value="";
		} else if(parseFloat(value)<0) {
			parent.swal("请输入大于0的数值!");
			obj.value="";
		}
	}
	function _changeUseCalcType(){
		var useCalcType = $("#useCalcType").val();
		if(useCalcType=="2"){
			$("#giftType").val("2");
			$("#giftType").attr("disabled", "disabled"); 
		}else{
			$("#giftType").removeAttr("disabled"); 
		}
	}
	function _checkAll(){
		var checkAll = $("input[name=checkboxAll]").attr("checked");
		if(checkAll=="checked"){
			$("input[name=productId]").prop("checked", true); 
		}else{
			$("input[name=productId]").prop("checked", false); 
		}
	}
</script>
  </head>
  
  <body style="font-family: '微软雅黑';">
  <div id="contentDiv" style="padding:4px; width:99%;">
		<div class="colnums-2-ab-b">
  <!-- <div id="contentDiv"> -->
  <input name="fgId" id="fgId" type="hidden" value="${fgId }" />
   <!--  <div class="colnums-2-ab-b"> -->
    	<div class="toptil">${title }</div>
		<div class="search_item" style="width:100%;" ><!--search_item S-->
		<div class="item_left" style="width: 80%;padding:0px;height:140px;"><!--item_left S-->
			<table style="width: 100%;border-collapse:separate;margin:10px; border-spacing:0px 10px;">
				<tr>
					<td style="vertical-align: middle" nowrap >活动名称:</td>
					<td style="vertical-align: middle">
						<input name="fgName" id="fgName" type="text" value="${bean.FG_NAME}" defaultval="满赠活动名称" onblur="clearDefaultVal('fgName',2,'满赠活动名称',this.value)"  onfocus="clearDefaultVal('fgName',1,'',this.value)" style="width: 130px;height: 18px; padding-left: 3px;color:black;" /></td>
					<td style="vertical-align: middle" nowrap>开始时间:</td>
					<td style="vertical-align: middle">
						<input type="text" id="begTime" name="begTime" onClick="WdatePicker({position:{left:301,top:91},dateFmt:'yyyy-MM-dd HH:mm:ss'})" 
							style="width: 130px;height: 18px; padding-left: 3px;color:black;"  class="Wdate" value="${bean.BEGTIME}"/> </td>
					<td style="vertical-align: middle" nowrap>结束时间:</td>
					<td style="vertical-align: middle">
						<input type="text" id="endTime" name="endTime" onClick="WdatePicker({position:{left:527,top:91},dateFmt:'yyyy-MM-dd HH:mm:ss'})" 
							style="width: 130px;height: 18px; padding-left: 3px;color:black;"  class="Wdate" value="${bean.ENDTIME}"/> </td>
				</tr>
				<tr>
            		<td style="vertical-align: middle" nowrap>使用类型:</td>
					<td style="vertical-align: middle">
						<select class="s_list" id="useType" name="useType" style="width: 130px;height: 18px;">
							<option value="1">满金额</option>
							<option value="2">满数量</option>
            			</select>
					</td>
					<td nowrap>状<span style="color: #FAFAFA">一一</span>态:</td>
					<td style="vertical-align: middle">
						<select class="s_list" id="status" name="status" style="width: 130px;height: 18px;">
							<option value="1">启用</option>
							<option value="0">禁用</option>
            			</select>
            		</td>
					<td style="vertical-align: middle" nowrap>是否倍减:</td>
					<td style="vertical-align: middle"><select class="s_list" id="timesFg" name="timesFg" style="width: 130px;height: 18px;">
						<option value="0">否</option>
						<option value="1">是</option>
	           			</select>
	           		</td>
				</tr>
				<tr>
					<td style="vertical-align: middle" nowrap>使用条件:</td>
					<td style="vertical-align: middle"><input type="text" id="useCondition" name="useCondition" style="width: 130px;height: 18px; padding-left: 3px;color:black;" value="${bean.USE_CONDITION }" onchange="_checkZhekou(this)"/> </td>
					<td style="vertical-align: middle" nowrap>计算方式:</td>
					<td style="vertical-align: middle"><select class="s_list" id="useCalcType" name="useCalcType" style="width: 130px;height: 18px;" onchange="_changeUseCalcType()">
						<option value="1">单品分别计算</option>
						<option value="2">多商品混合计算</option>
	           			</select>
	           		</td>
					<td style="vertical-align: middle" nowrap>赠品类型:</td>
					<td style="vertical-align: middle"><select class="s_list" id="giftType" name="giftType" style="width: 130px;height: 18px;">
						<option value="1">同种商品</option>
						<option value="2">自定义</option>
	           			</select>
	           		</td>
				</tr>
				<tr>
					<td style="vertical-align: middle" nowrap>范<span style="color: #FAFAFA">一一</span>围:</td>
					<td style="vertical-align: middle"><select class="s_list" id="fgRange" name="fgRange" style="width: 130px;height: 18px;" onchange="_viewProductList()">
						<option value="1">全店</option>
						<option value="2">商品</option>
	           			</select>
	           		</td>
				</tr>
			</table>
			
		</div><!--item_left E-->
		<div class="item_right"  style="width:19%;padding:0px;height:140px;text-align: center; line-height: 140px;">
			<div>
			<button id="submitformdata" class="orange_search_btn3" onclick="_add()" >保存</button>
			<button id="submitformdata1" class="" onclick="" style="display: none;"></button>
			<button id="cancleBtn" class="orange_search_btn3" onclick="window.history.go(-1);" >返回</button>
			</div>
		</div>
	</div>
	    <div id="productList" class="row-fluid dataTables_wrapper" style="width:100%;">
	   <div class="colnums-2-ab-b">
		   <div class="search_lis" style="width: 80%;padding: 10px 0px"><!--search_lis S-->
		       <div class="search_lis_se"><!--search_lis_se S-->
		          <span style="margin-left: 10px;">商品标题:</span>  
		          <input name="querytitle" id="queryTitle" type="text" class="in_bit" maxlength="40" style="color:black;" value="" >
		            <span style="margin-left: 5px;">价格:</span>
		            <input name="minPriceStr" id="minPriceStr" type="text" class="in_price"  maxlength="10" style="color:#000000"  value="">
		            <i>-</i>
		            <input name="maxPriceStr" id="maxPriceStr" type="text" class="in_price"  maxlength="10" style="color:#000000"  value="">
		            
		            <span style="margin-left: 10px;">分类:</span><select id="firstSeries" name="firstSeries" autocomplete="off" onchange="_getSelect()" style="height: 22px;">
				           		<option value="0">全部</option>
						   		<c:forEach items="${yjfl}" var="y">
						   			<option value="<c:out value='${y.PRODUCT_TYPE_CODE}'/>" >
						   			<c:out value='${y.PRODUCT_TYPE_NAME}'/></option>
						   		</c:forEach>
			        </select>
			      
			        <select name="secondSeries" id="secondSeries" autocomplete="off" style="height: 22px; margin-left: 5px;margin-right: 20px;">
			        </select>
		            <button type="button" class="cxx_btn" onclick="_initDataList()" >查询</button>
		        </div>
		    </div>
	    </div>
				<table id="listTable"
					class="table table-hover table-nomargin table-bordered usertable dataTable"
					style="width: 100%; border-spacing: 0;margin-bottom: 30px;">
					<thead>
						<tr class="trBgd"
							style="background-color: #eee;text-align: center; height: 31px; border: 1px solid #ddd; white-space: nowrap; background-position: 0 -123px; line-height: 30px; font-weight: bold;">
							<th class="t1" style="text-align:center;vertical-align: middle;width: 4%" >
								<input type='checkbox' name='checkboxAll' value='' onclick="_checkAll()">
							</th>
			                <th class="t2" style="text-align:center;vertical-align: middle" >图片</th>
			                <th class="t4" style="text-align:center;vertical-align: middle" >商品</th>
			                <th class="t4" style="text-align:center;vertical-align: middle" ><span style="color: black;">价格</span></th>
			                <th class="t4" style="text-align:center;vertical-align: middle" ><span style="color: black;">库存</span></th>
			                <th class="t4" style="text-align:center;vertical-align: middle" ><span style="color: black;">上架时间</span></th>
						</tr>
					</thead>
					<tbody id="ajaxSerieslist">
					</tbody>
				</table>
				<div id="pagination"></div>
			</div>

<!-- InstanceEndEditable -->
  </div><!--colnums-2-ab-b begin-->
<div class="clear" style="height:30px;"></div>


</div>

  </body>
</html>
